package com.zh.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zh.common.BaseResponse;
import com.zh.common.ErrorCode;
import com.zh.common.ResultUtils;
import com.zh.domain.dto.milestone.AddMileStoneRequest;
import com.zh.domain.dto.milestone.UpdateMileStoneRequest;
import com.zh.domain.vo.milestone.MileStoneVo;
import com.zh.domain.vo.task.TaskCountVo;
import com.zh.exception.ThrowUtils;
import com.zh.service.*;
import com.zh.service.ProjectDynamicsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "MilestoneController", value = "里程碑控制器")
@RestController
@RequestMapping("/milestone")
@Slf4j
@SaCheckLogin
public class MilestoneController {


    private final MilestoneService milestoneService;
    private final UserService userService;
    private final ProjectService projectService;

    private final ProjectUserService projectUserService;

    private final ProjectDynamicsService projectDynamicsService;

    private final MessageService messageService;

    public MilestoneController(MilestoneService milestoneService,
                               UserService userService,
                               ProjectService projectService,
                               ProjectUserService projectUserService,
                               ProjectDynamicsService projectDynamicsService,
                               MessageService messageService) {
        this.milestoneService = milestoneService;
        this.userService = userService;
        this.projectService = projectService;
        this.projectUserService = projectUserService;
        this.projectDynamicsService = projectDynamicsService;
        this.messageService = messageService;
    }

    @PostMapping("/add")
    @ApiOperation(value = "addMilestone", notes = "新增里程碑")
    public BaseResponse<Boolean> addMilestone(@RequestBody AddMileStoneRequest addMileStoneRequest) {
        //1.参数校验
        ThrowUtils.throwIf(null == addMileStoneRequest, ErrorCode.PARAMS_ERROR);
        Boolean result = milestoneService.add(addMileStoneRequest);
        return ResultUtils.success(result);
    }

    @PostMapping("/update")
    @ApiOperation(value = "updateMilestone", notes = "更新里程碑")
    public BaseResponse<Boolean> updateMilestone(@RequestBody UpdateMileStoneRequest updateMileStoneRequest) {
        //1.参数校验
        ThrowUtils.throwIf(null == updateMileStoneRequest, ErrorCode.PARAMS_ERROR);
        Boolean result = milestoneService.updateMileStone(updateMileStoneRequest);
        return ResultUtils.success(result);
    }
    @GetMapping
    @ApiOperation(value = "getMilestone", notes = "id获取里程碑列表")
    public BaseResponse<MileStoneVo> getMilestone(Integer id){
        ThrowUtils.throwIf(null ==id, ErrorCode.PARAMS_ERROR);
        MileStoneVo result = milestoneService.getMileStoneById(id);
        return ResultUtils.success(result);
    }

    @GetMapping("/taskCount")
    @ApiOperation(value = "getTaskCount", notes = "获取里程碑任务统计信息")
    public BaseResponse<TaskCountVo> getTaskCountByMileId(Integer mileId) {
        TaskCountVo taskCountVo = milestoneService.getTaskCount(mileId);
        return ResultUtils.success(taskCountVo);
    }
}
